package week2;

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
public class week_08 {

	public static void main(String[] args) {
		ArrayList strList = new ArrayList(); 
		ArrayList strList1 = new ArrayList();
		Scanner sc = new Scanner(System.in 

);
		//while(true){
		String str = sc.next();
		while(!str.equals("!!end!!")){
			strList.add(str);
			str = sc.next();
		}
		strList.add(0, "begin");
		strList.add("end");
		System.out.println(strList);
		String a = sc.next();
		System.out.println(strList.contains(a));
		System.out.println(strList.indexOf(a));
		System.out.println(strList.lastIndexOf(a));
		System.out.println((String)strList.get(0));
		strList.remove(0);
		System.out.println(strList);
		String b = sc.next();
		strList.set(1, b);
		System.out.println(strList);
		String c = sc.next();
		for(int i=0;i<strList.size();i++){
			String d = (String)strList.get(i);
			if(d.indexOf(c)!=-1)
				strList1.add(d);
				
		}
		System.out.println(strList1);
		int n = strList.indexOf(c);
		if(n>=0)
		strList.remove(n);
		System.out.println(strList);
		strList.clear();
		System.out.println(strList+" "+strList.size()+","+strList.isEmpty());
		strList1.clear();

	}

}
//}